/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exportsql;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author feng
 */
public class Utils {

    public static String[] getLocalIp() throws Exception {

        NetworkInterface ne = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
        List<String> ipList = new ArrayList<String>();
        Enumeration<InetAddress> e = ne.getInetAddresses();
        while (e.hasMoreElements()) {
            ipList.add(e.nextElement().getHostAddress());
        }
        return ipList.toArray(new String[0]);
    }

    public static void main(String[] args) throws Exception {
        List<String> list = new ArrayList<String>();
        list.add("sdfs");
        list.add("sdfs");
        list.add("sdfs");
        System.out.println(join(list));
    }

    public static String join(List<?> list) {
        StringBuilder str = new StringBuilder();
        for (Iterator<?> it = list.iterator(); it.hasNext();) {
            Object obj = it.next();
            str.append(obj.toString());
            if (it.hasNext()) {
                str.append(",");
            }
        }
        return str.toString();
    }
}
